//
//  KLDataStrongboxView.m
//  设置数据保险箱自定义视图
//
//  Created by 华杨科技 on 2017/4/21.
//  Copyright © 2017年 饶波. All rights reserved.
//  设置数据保险箱自定义视图

#import "KLDataStrongboxView.h"
#import "HemaConst.h"

#define kLabel_W 90
#define kLabel_H 40
#define kSpace 30  // 上下行之间间距
@interface KLDataStrongboxView()
@property (nonatomic, strong) UILabel *warningLB; // 警告label
@property (nonatomic, strong) UIButton *sureBtn; // 确定label

@end

@implementation KLDataStrongboxView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        NSLog(@"****** %s%d",__FUNCTION__,__LINE__);
        
         // 只创建view 不设置frame
        [self setupUI];
        
    }
    return self;
}

// 创建UI控件
- (void)setupUI {
    
    NSLog(@"====== %s%d",__FUNCTION__,__LINE__);
    // 只创建view 不设置frame
    self.pwdLabel = [[UILabel alloc] init];
    [self addSubview:self.pwdLabel];
    self.pwdTextfield = [[UITextField alloc] init];
    self.pwdTextfield.placeholder = @"密码为6位纯数字";
    self.pwdTextfield.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.pwdTextfield.borderStyle = UITextBorderStyleRoundedRect; // 边框
    [self addSubview:self.pwdTextfield];
    
    self.surepwdLabel = [[UILabel alloc] init];
    [self addSubview:self.surepwdLabel];
    self.surepwdTextfield = [[UITextField alloc] init];
    self.surepwdTextfield.placeholder = @"请输入确认密码";
    self.surepwdTextfield.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.surepwdTextfield.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:self.surepwdTextfield];
    
    self.warningLB = [[UILabel alloc] init];
    self.warningLB.font = [UIFont systemFontOfSize:14.0];
    self.warningLB.textAlignment = NSTextAlignmentCenter;
    self.warningLB.numberOfLines = 0;
    self.warningLB.textColor = [UIColor redColor];
    self.warningLB.text = @"数据保险箱密码不可找回。因此请您牢记并妥善保管数据保险箱密码，以免给您的生活造成不必要的麻烦和损失!";
    [self addSubview:self.warningLB];
    
    self.sureBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.sureBtn.backgroundColor = [UIColor blueColor];
    NSString *btnTitle = @"提交";
    [self.sureBtn setTitle:btnTitle forState:UIControlStateNormal];
    [self.sureBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    self.sureBtn.clipsToBounds = YES;
    self.sureBtn.layer.cornerRadius = 5;
    [self addSubview:self.sureBtn];
    
}

// 设置frame
- (void)layoutSubviews {
    NSLog(@"---%s%d",__FUNCTION__,__LINE__);
    
    [super layoutSubviews];
    // 保险箱密码
    self.pwdLabel.frame = CGRectMake(20, 0, kLabel_W, kLabel_H);
    self.pwdTextfield.frame = CGRectMake(kLabel_W + 20 + 20, 0, UI_View_Width - 60 - kLabel_W, kLabel_H);
    
    // 确认密码
    self.surepwdLabel.frame = CGRectMake(20, kLabel_H + kSpace, kLabel_W, kLabel_H);
    self.surepwdTextfield.frame = CGRectMake(kLabel_W + 20 + 20, kLabel_H + kSpace, UI_View_Width - 60 - kLabel_W, kLabel_H);
    
    self.warningLB.frame = CGRectMake(20, 2*(kLabel_H + kSpace), UI_View_Width - 40, 60);
    
    self.sureBtn.frame = CGRectMake(20, 2*(kLabel_H + kSpace) + 60 + 10, UI_View_Width - 40, 50);
}

/**设置label的标题*/
- (void)pwdLabelString:(NSString *)pwdlabelStr surepwdLabelString:(NSString *)surepwdLabelStr {
    self.pwdLabel.text = pwdlabelStr;
    self.surepwdLabel.text = surepwdLabelStr;
}

/**通过block把button传出去,在VC实现button的点击事件*/
- (void)clickButton:(void(^)(UIButton *sender))completionHandler {
    completionHandler(self.sureBtn);
}



@end
